package com.xtoad.demo.rpc.consumer.controller;


import com.xtoad.demo.rpc.api.entity.User;
import com.xtoad.demo.rpc.api.service.UserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户控制器
 *
 * @author xtoad
 * @date 2021-10-14
 */
@RestController
@RequestMapping("/users")
public class UserController {

    @DubboReference(version = "${xtoad.rpc.service.version}", protocol = "dubbo")
    private UserService userService;

    /**
     * 根据ID取得用户信息
     *
     * @param id 用户ID
     * @return 用户信息
     */
    @GetMapping("/{id}")
    public User getUserById(@PathVariable Integer id) {
        return userService.getUserById(id);
    }
}
